import time

from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.extensions.android.gsm import GsmCallActions
from selenium.webdriver import ActionChains
from selenium.webdriver.support import expected_conditions

from utils import *


class TestBrowser:
    def setup(self):
        desired_caps = {
            'platformName': 'Android',
            'platformVersion': '6.0.1',
            'deviceName': 'emulator-5554',
            'resetKeyBoard': True,
            'unicodeKeyboard': True,
            'noReset': True,
            # "dontStopAppOnReset": True,
            'automationName': 'Uiautomator2',
            # "browser": "Browser",
            "appPackage": "com.xueqiu.android",
            "appActivity": ".common.MainActivity",
            # "chromedriverExecutable": "/usr/local/lib/node_modules/appium/node_modules/appium-chromedriver/chromedriver/mac/chromedriver77",
            "chromedriverExecutableDir": "/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-chromedriver/chromedriver/mac/chromedriver75",
        }

        self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
        self.driver.implicitly_wait(5)

    def test_xueqiu(self):
        change_btn = By.XPATH, '//*[@text="交易"]'
        get_element(self.driver, change_btn).click()
        time.sleep(3)
        print(self.driver.contexts)
        self.driver.switch_to.context(self.driver.contexts[-1])
        fund_open = By.XPATH, '//*[@text="基金开户"]'
        get_element(self.driver, fund_open).click()
        print(self.driver.contexts)

        time.sleep(3)


